home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 3_0 / DOUBLEDE / ZOOM.C < prev   
C/C++ Source or Header  |  1988-01-18  |  3KB  |  155 lines

  1. #include "MacTypes.h"
  2. #include "Quickdraw.h"
  3. #include "WindowMgr.h"
  4. #include "MemoryMgr.h"
  5.  
  6. /*******************************************************************
  7.  
  8.         Loose translation of ZoomRects() from an early release
  9.         of the Apple Software Supplement.
  10.         
  11. *******************************************************************/
  12. #define        ONE         65536L
  13. #define        ZOOMSTEPS    16
  14.  
  15. Fixed    fract;
  16.  
  17. int blend(i1,i2)
  18. int    i1,i2;
  19.     {
  20.     Fixed    smallFix,bigFix,tempFix;
  21.  
  22.     smallFix = ONE * i1;
  23.     bigFix = ONE * i2;
  24.     tempFix = FixMul(fract,bigFix)+FixMul(ONE-fract,smallFix);
  25.     return(FixRound(tempFix));
  26.     }
  27.  
  28. zoomrect(smallrect,bigrect,zoomup)
  29. Rect    *smallrect,*bigrect;
  30. Boolean    zoomup;
  31. {
  32.     Fixed    factor;
  33.     Rect    rect1,rect2,rect3,rect4;
  34.     GrafPtr    savePort,deskPort;
  35.     int        i;
  36.     
  37.     GetPort(&savePort);
  38.     OpenPort(deskPort = (GrafPtr)NewPtr(sizeof(GrafPort)));
  39.     InitPort(deskPort);
  40.     SetPort(deskPort);
  41.     PenPat(gray);
  42.     PenMode(notPatXor);
  43.     if (zoomup)
  44.         {
  45.         rect1 = *smallrect;
  46.         factor = FixRatio(6,5);
  47.         fract = FixRatio(541,10000);
  48.         }
  49.     else
  50.         {
  51.         rect1 = *bigrect;
  52.         factor = FixRatio(5,6);
  53.         fract = ONE;
  54.         }
  55.     rect2 = rect1;
  56.     rect3 = rect1;
  57.     FrameRect(&rect1);
  58.     for (i=1;i<=ZOOMSTEPS;i++)
  59.         {
  60.             rect4.left = blend(smallrect->left,bigrect->left);
  61.             rect4.right = blend(smallrect->right,bigrect->right);
  62.             rect4.top = blend(smallrect->top,bigrect->top);
  63.             rect4.bottom = blend(smallrect->bottom,bigrect->bottom);
  64.             FrameRect(&rect4);
  65.             FrameRect(&rect1);
  66.             rect1 = rect2;
  67.             rect2 = rect3;
  68.             rect3 = rect4;
  69.             fract = FixMul(fract,factor);
  70.         }
  71.     FrameRect(&rect1);
  72.     FrameRect(&rect2);
  73.     FrameRect(&rect3);
  74.     ClosePort(deskPort);
  75.     DisposPtr((Ptr)deskPort);
  76.     PenNormal();
  77.     SetPort(savePort);
  78. }
  79.  
  80. /********************************************************************
  81.  
  82.         ltog(r)
  83.         Rect        *r;
  84.     
  85.     Converts the Rect referenced by *r from local to global
  86.     coordinate system.
  87.  
  88. *******************************************************************/
  89. ltog(r)
  90. Rect    *r;
  91.     {
  92.     Point    p1,p2;
  93.  
  94.     p1 = topLeft(*r);
  95.     p2 = botRight(*r);
  96.     LocalToGlobal(&p1);
  97.     LocalToGlobal(&p2);
  98.     Pt2Rect(p1,p2,r);
  99.     }
  100.  
  101. gtol(r)
  102. Rect    *r;
  103. {
  104.     Point    p1,p2;
  105.     p1 = topLeft(*r);
  106.     p2 = botRight(*r);
  107.     GlobalToLocal(&p1);
  108.     GlobalToLocal(&p2);
  109.     Pt2Rect(p1,p2,r);
  110. }
  111.  
  112. /********************************************************************
  113.  
  114.         zoomport(wind,up)
  115.         WindowPtr    wind;
  116.         Boolean        up;
  117.     
  118.     Zooms the window referenced by "wind" either from an inivisible
  119.     state to a visible state, or vice versa.  Pass TRUE in the "up"
  120.     Boolean parameter to zoom a window to open, an FALSE to zoom
  121.     it close.  The WindowPtr must have already been created elsewhere,
  122.     and zooming the window invisible only hides the window, it does
  123.     not destroy the WindowPtr data.
  124.     
  125. ********************************************************************/
  126. zoomport(wind,up)
  127. WindowPtr    wind;
  128. Boolean        up;
  129.     {
  130.     Rect    r1,r2,r3;
  131.  
  132.     SetPort(wind);
  133.     SetRect(&r1,0,20,0,20);
  134.     r3 = wind->portRect;
  135.     r2 = r3;
  136.     InsetRect(&r2,(r3.right-r3.left+20)/2,(r3.bottom-r3.top+20)/2);
  137.  
  138.     ltog(&r2);
  139.     ltog(&r3);
  140.  
  141.     if (up)
  142.         {
  143.         zoomrect(&r1,&r2,TRUE);
  144.         zoomrect(&r2,&r3,TRUE);
  145.         ShowWindow(wind);
  146.         SetPort(wind);
  147.         }
  148.     else
  149.         {
  150.         HideWindow(wind);
  151.         zoomrect(&r2,&r3,FALSE);
  152.         zoomrect(&r1,&r2,FALSE);
  153.         }
  154.  
  155.     }